﻿using MyFramework.Common;
using MyFramework.Common.Interfaces;

namespace MyFramework.Core
{
    /// <summary>
    /// Model base
    /// </summary>
    public abstract class ModelBase : Entity, IModel
    {
        #region Fields

        /// <summary>
        /// The setting
        /// </summary>
        private ISettings _setting;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelBase"/> class.
        /// </summary>
        public ModelBase()
        {
            this.Initialize();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the setting.
        /// </summary>
        /// <value>
        /// The setting.
        /// </value>
        public ISettings Setting
        {
            get { return this._setting; }
            set { if (this._setting != value) { this._setting = value; RaisePropertyChangedEvent(() => Setting); } }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected abstract void Initialize();

        /// <summary>
        /// Saves the settings.
        /// </summary>
        public virtual void SaveSettings()
        {
        }

        /// <summary>
        /// Loads the settings.
        /// </summary>
        public virtual void LoadSettings()
        {
        }

        /// <summary>
        /// Determines whether this instance is valid.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if this instance is valid; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsValid()
        {
            return true;
        }

        #endregion
    }
}
